//
//  DDWaitInterviewTypeCell.swift
//  DingDongZP
//
//  Created by ZZN on 16/10/25.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit




//选择cell
class DDWaitInterviewTypeCellVideoCell: LDBaseCells {
    
    /// 根据type判断是否可编辑
    var interViewType:DDWaitInterviewType? {
        
        didSet{
            
            if interViewType == .Video {
            
                videoBtn.setBackgroundImage(UIImage.init(named: "common_interview_btn_icon"), forState: .Normal)
                videoBtn.setTitle("在线面试", forState: UIControlState.Normal)
            } else {
                
                videoBtn.setBackgroundImage(UIImage.init(named: "common_interview_btn_icon"), forState: .Normal)
                videoBtn.setTitle("到场面试", forState: UIControlState.Normal)
            }
        }
    }
    
    var lineView = { return UIImageView.setupDivideLine_H(LDFrame.ScreenWidth) }()
    
    var titleLab = { return UILabel.setDetailsLab("title", fontSize: 16, titleColor: LDFontColor.LightBlack, Alignment: .Left) }()
    

    var videoBtn:UIButton!
    
    var presentBtn:UIButton!
    
    override init(type: LDBaseCellType, margin: CGFloat, style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(type: type, margin: margin, style: .Default, reuseIdentifier: reuseIdentifier)
        initUI()
        
    }
  

    
    func initUI() {
        
        backgroundColor = LDGolbalColor.BgGoundGray
        videoBtn = creatBtn("在线面试")
        presentBtn = creatBtn("到场面试")
        presentBtn.hidden = true
        
//        presentBtn.setBackgroundImage(UIImage.init(named: "common_interview_btn_icon"), forState: .Selected)
//        videoBtn.setBackgroundImage(UIImage.init(named: "common_interview_btn_icon"), forState: .Normal)
        
        addSubview(titleLab)
        addSubview(videoBtn)
        addSubview(presentBtn)
        addSubview(lineView)
        
        titleLab.snp_makeConstraints { (make) in
            
            make.centerY.equalTo(self)
            make.left.equalTo(LDCellFrame.Margin_Left)
            make.size.equalTo(CGSizeMake(80, 25))
            
        }
        
        videoBtn.snp_makeConstraints { (make) in
            
            make.centerY.equalTo(self)
            make.left.equalTo(titleLab.snp_right).offset(LDMargin_H*3)
            make.size.equalTo(CGSizeMake(80, 25))
            
        }
        
        presentBtn.snp_makeConstraints { (make) in
            
            make.centerY.equalTo(self)
            make.left.equalTo(videoBtn.snp_right).offset(LDMargin_H*3)
            make.size.equalTo(CGSizeMake(80, 25))
            
        }
        
        lineView.snp_makeConstraints { (make) in
            
            make.left.equalTo(LDMargin_V*2)
            make.right.equalTo(-LDMargin_V*2)
            make.height.height.equalTo(0.5)
            make.bottom.equalTo(self)
        }
        
    }
    
    //
    func creatBtn(title:String) ->UIButton {
        
        let btn = UIButton.setDetailsBtn(title, picName: "", btnBackColor: nil, titleColor: LDFontColor.DeepGray)
        btn?.setBackgroundImage(UIImage(named:"common_interview_btn_icon"), forState: .Selected)
        btn?.titleLabel?.font = LDFont.Font13
        
        btn?.enabled = false
        btn?.layer.cornerRadius = 3
        
        btn?.layer.borderWidth = 0.5
        btn?.layer.borderColor = LDFontColor.LightGray.CGColor
        btn?.layer.masksToBounds = true
        btn?.selected = true
        
        return btn!
    }
    
    required init?(coder aDecoder: NSCoder) {
        
        fatalError("init(coder:) has not been implemented")
    }
    
    
}

//内容cell
class DDWaitInterviewTypeCellVideoDescCell: LDBaseCells {
    
    
    var descTitle:String?
    var interViewType:DDWaitInterviewType?
    var lineView = { return UIImageView.setupDivideLine_H(LDFrame.ScreenWidth) }()
    
    var titleLab = { return UILabel.setDetailsLab("title", fontSize: 16, titleColor: LDFontColor.LightBlack, Alignment: .Left) }()
    var descTextView:UITextView = {
        
        let textV = UITextView()
    
        textV.editable = false
        textV.font = LDFont.Font14
        textV.textColor = LDFontColor.DeepGray
        return textV
    
    }()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initData()
    }
    
    func initData() {
        
        //是否启动编辑模式
//        rac_valuesAndChangesForKeyPath("interViewType", options: NSKeyValueObservingOptions.New, observer: nil).subscribeNext { [weak self] (obj) in
//            
//            let type = obj as? DDWaitInterviewType
//            
//            if type == .Show {
//                
//                self?.descTextView.editable = false
//            }
//        }
        //是否变换行高
        descTextView.rac_signalForSelector(#selector(self.textViewDidChange(_:)), fromProtocol:UITextViewDelegate.self).subscribeNext { (obj) in
            
//            print(obj)
        }
    }
    
    
    func initUI() {
        
        descTextView.delegate = self
        descTextView.allowsEditingTextAttributes = true
        descTextView.scrollEnabled = false
        
        
        addSubview(titleLab)
        addSubview(descTextView)
        addSubview(lineView)
        
        titleLab.snp_makeConstraints { (make) in
            
            make.centerY.equalTo(self)
            make.left.equalTo(LDCellFrame.Margin_Left)
            make.size.equalTo(CGSizeMake(80, 25))
            
        }
        
        descTextView.snp_makeConstraints { (make) in
            
            make.left.equalTo(titleLab.snp_right).offset(LDMargin_V*2)
            make.right.equalTo(-LDMargin_V)
            make.top.equalTo(titleLab)
            make.bottom.equalTo(-LDMargin_V*3)
        }
        
        lineView.snp_makeConstraints { (make) in
            
            make.left.equalTo(LDMargin_V*2)
            make.right.equalTo(-LDMargin_V*2)
            make.height.height.equalTo(0.5)
            make.bottom.equalTo(self)
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
}

extension DDWaitInterviewTypeCellVideoDescCell:UITextViewDelegate {
    
    //delegate
    func textViewDidChange(textView: UITextView) {
        
    }
}


//class DDWaitInterviewTypeCell: LDBaseCells {
//    
//    var interViewType:DDWaitInterviewType?
//    
//    var cellTitleArr = ["面试类型","面试时间","联系方式","面试地点","其它说明"]
//    override init(type: LDBaseCellType, margin: CGFloat, style: UITableViewCellStyle, reuseIdentifier: String?) {
//        super.init(type: type, margin: margin, style: .Default, reuseIdentifier: reuseIdentifier)
//        
//    }
//    
//    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
//}